var moment=require('moment');
var delay=1000;
module.exports={
    delay: function (name,cb,timeout) {
        timeout=timeout || Math.random()*delay|0;
        setTimeout(function () {
            cb(null,name+' delay: '+timeout+' ms');
        },timeout);
    },
    error: function (errMsg,cb,timeout) {
        timeout=timeout || Math.random()*delay|0;
        setTimeout(function () {
            cb(errMsg);
        },timeout);
    },
    log:function() {
        //对console.log进行了封装。主要是增加了秒钟的输出，通过秒数的差值方便大家对async的理解。
        process.stdout.write(moment().format('ss.SSS')+'> ');
        console.log.apply(console,arguments);

    },
    inc:function(n, callback, timeout) {
        //将参数n自增1之后的结果返回给async
        timeout = timeout || Math.random()*delay|0;
        setTimeout(function() {
            callback(null, n+1);
        }, timeout);
    },
    get: function (url,cb,timeout) {
        timeout = timeout || Math.random()*delay|0;
        setTimeout(function () {
            cb(null,['<html><title>',url.split('.')[1],'</title></html>'].join(' '));
        },timeout);
    }
}